package com.techblor.wechat.library.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * 微信配置
 */
@Data
@Validated
@Component
@ConfigurationProperties(prefix = "wechat")
public class WechatProperties {

    /**
     * 小程序配置
     */
    private MiniprogramProperties miniprogram;

    /**
     * 公众号配置
     */
    private OfficialAccountProperties officialAccount;

    /**
     * 企业微信配置
     */
    private WorkProperties work;

    /**
     * 小程序配置
     */
    @Data
    @Validated
    public static class MiniprogramProperties {
        /**
         * AppID
         */
        @NotBlank(message = "wechat miniprogram appId cannot be empty")
        private String appId;

        /**
         * AppSecret
         */
        @NotBlank(message = "wechat miniprogram appSecret cannot be empty")
        private String appSecret;
    }

    /**
     * 公众号配置
     */
    @Data
    @Validated
    public static class OfficialAccountProperties {
        /**
         * AppID
         */
        @NotBlank(message = "wechat official account appId cannot be empty")
        private String appId;

        /**
         * AppSecret
         */
        @NotBlank(message = "wechat official account appSecret cannot be empty")
        private String appSecret;

        /**
         * 原始ID
         */
        private String originalId;

        /**
         * 微信服务器
         */
        private OfficialAccountProperties.ServerProperties server;

        /**
         * 服务器
         */
        @Data
        @Validated
        public static class ServerProperties {

            /**
             * 服务器地址
             */
            @NotBlank(message = "wechat official account server url cannot be empty")
            private String url;

            /**
             * 令牌
             */
            @NotBlank(message = "wechat official account server token cannot be empty")
            private String token;

            /**
             * 消息加解密密钥
             */
            @NotBlank(message = "wechat official account server encodingAESKey cannot be empty")
            private String encodingAESKey;
        }
    }

    /**
     * 企业微信配置
     */
    @Data
    @Validated
    public static class WorkProperties {

        /**
         * corpid
         */
        @NotBlank(message = "wechat work corpid cannot be empty")
        private String corpid;

        /**
         * secret
         */
        @NotNull(message = "wechat work corpsecret cannot be empty")
        private Corpsecret corpsecret;

        /**
         * 密钥
         */
        @Data
        @Validated
        public static class Corpsecret {

            /**
             * 通讯录
             */
            private String contacts;

            /**
             * 客户联系
             */
            private String customer;

        }
    }
}
